package com.kagura.restdemo.service.impl;

import com.kagura.restdemo.dao.UserDao;
import com.kagura.restdemo.pojo.User;
import com.kagura.restdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PACKAGE_NAME: com.kagura.restdemo.service.impl
 * @CLASS_NAME: UserServiceImpl
 * @USER: kagura
 * @Description TODO
 * @Date 2021/5/28 5:44 下午
 * @MONTH_NAME_FULL: 五月
 * @DAY: 28
 * @DAY_NAME_FULL: 星期五
 * @PROJECT_NAME: restDemo
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public boolean addUser(User user) {
        boolean flag = false;
        try {
            userDao.addUser(user);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean updateUser(User user) {
        boolean flag = false;
        try {
            userDao.updateUser(user);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean deleteUser(int id) {
        boolean flag = false;
        try {
            userDao.deleteUser(id);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public List<User> findByName(String name) {
        return userDao.findByName(name);
    }

    @Override
    public List<User> findAllUsers() {
        return userDao.findAllUsers();
    }
}
